<template>
	<view>
		<uni-forms :modelValue="Expense">
			<uni-forms-item label="ID" v-if="false" >
				<uni-easyinput v-model="Expense.expenseId" />
			</uni-forms-item>
			<uni-forms-item label="用户ID" v-if="false" >
				<uni-easyinput v-model="Expense.userId"/>
			</uni-forms-item>
			<uni-forms-item label="描述">
				<uni-easyinput  v-model="Expense.expenseDescription" />
			</uni-forms-item>
			<uni-forms-item label="金额">
				<uni-easyinput type="number" v-model="Expense.expenseAmount" />
			</uni-forms-item>	
			<uni-forms-item label="日期时间">
				<uni-datetime-picker type="datetime" v-model="Expense.expenseDate"/>
			</uni-forms-item>
			<uni-forms-item label="支出类别">
				<uni-easyinput  v-model="Expense.expenseCategory" />
			</uni-forms-item>		
		</uni-forms>
		<button type="primary" size="mini" @click="submit()">保存</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Expense: {
					expenseId:"",
					userId:"",
					expenseDescription:"",
					expenseDate:"",
					expenseCategory:"",
					expenseAmount:"",
					year:"",
					month:"",
				}
			}
		},
		onLoad() {
			uni.getStorage({
				key:'token',
				success: res=>{
					// console.log(res.data);
					this.token=res.data
				}
			});
			uni.getStorage({
				key : 'user',
				success: res=>{
					console.log(res.data.userId);
					this.Expense.userId=res.data.userId
				}
			});
			
		},
		methods: {
			submit(){
				uni.request({
					url:'http://8.130.170.106:9999/expense/insert',
					data:{
						userId: this.Expense.userId,
						expenseDescription: this.Expense.expenseDescription,
						expenseAmount: this.Expense.expenseAmount,
						expenseDate: this.Expense.expenseDate,
						expenseCategory: this.Expense.expenseCategory
					},
					header:{
						token:this.token
					},
					success: (res) => {
						uni.navigateTo({
							url: '/pages/main/tabbar-3-detial/tabbar-3-expense/tabbar-3-expense',
							success: () => {
							  console.log("跳转成功");
							},
							fail: (err) => {
							  console.log("跳转失败", err);
							}
						});
					}
				})
			}
		}
	}
</script>

<style>
	.expenseDescription {
	  font-weight: bold;
	  font-size: 16px;
	}
	.button {
			display: flex;
			align-items: center;
			height: 35px;
			margin-left: 10px;
		}
</style>
